﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.ActiveRecord;
using System.Web;
using System.IO;

namespace Windvoice.Blog
{
    public partial class Friend : ActiveRecordBase<Friend>
    {
        public void SavePortrait(HttpPostedFileBase portraitFile)
        {
            string FileName = "/files/friend/" + Guid.NewGuid() + Path.GetExtension(portraitFile.FileName);
            string PhysicalPath = HttpContext.Current.Server.MapPath(FileName);

            if (!new FileInfo(PhysicalPath).Directory.Exists)
                new FileInfo(PhysicalPath).Directory.Create();

            portraitFile.SaveAs(PhysicalPath);

            this.Portrait = FileName;
        }

        public static Friend[] GetList(int pageIndex, int pageSize, out int recordCount)
        {
            recordCount = FindAll().Count();
            return FindAll().Skip((pageIndex - 1) * pageSize).Take(pageSize).ToArray();
        }
    }
}
